package com.base.cn.platform.os.service.course.material;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.common.service.CommonSetSubjectDataService;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.course.MaterialType;
import com.base.cn.platform.os.common.utils.file.FileDownloadUtil;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.dao.course.material.CouMaterialDao;
import com.base.cn.platform.os.entity.course.catalog.CourseCatalog;
import com.base.cn.platform.os.entity.course.catalog.CourseCatalogCondition;
import com.base.cn.platform.os.entity.course.cou.Course;
import com.base.cn.platform.os.entity.course.material.CouMaterial;
import com.base.cn.platform.os.entity.course.material.CouMaterialCondition;
import com.base.cn.platform.os.service.course.catalog.CourseCatalogBiz;
import com.base.cn.platform.os.service.course.cou.CourseBiz;
import com.base.cn.platform.os.service.manage.subject.SubjectService;
import com.base.cn.platform.os.service.manage.teacher.SysTeacherService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 素材Biz
 *
 * @author s.li
 * @create 2018-04-19-18:05
 */
@Service
public class CouMaterialBiz extends BaseBiz<CouMaterial,CouMaterialDao> {
    @Autowired
    private CouMaterialDao couMaterialDao;
    @Autowired
    private CommonSetSubjectDataService<CouMaterial> commonSetSubjectDataService;
    @Autowired
    private SysTeacherService sysTeacherService;
    @Autowired
    private SubjectService subjectService;
    @Autowired
    private CourseCatalogBiz courseCatalogBiz;
    @Autowired
    private CourseBiz courseBiz;
    @Autowired
    private Environment environment;

    /**
     * 查询数量
     * @param condition
     * @return
     */
    public BigDecimal count(CouMaterialCondition condition){
        return this.count(this.getWhereSql(condition));
    }
    /**
     * 保存素材数据
     * @param couMaterial 素材对象
     * @return CouMaterial
     */
    public CouMaterial saveMaterial(CouMaterial couMaterial ){
        if(DataUtil.idIsNotNull(couMaterial.getId())){//修改
            CouMaterial material = findById(couMaterial.getId());
            //播放码
            material.setPlayUrl(couMaterial.getPlayUrl());
            //直播数据，开始
            material.setRoomId(couMaterial.getRoomId());
            material.setTeacherCode(couMaterial.getTeacherCode());
            material.setStudentCode(couMaterial.getStudentCode());
            material.setAdminCode(couMaterial.getAdminCode());
            material.setLiveBeginTime(couMaterial.getLiveBeginTime());
            material.setLiveEndTime(couMaterial.getLiveEndTime());
            material.setPreEnterTime(couMaterial.getPreEnterTime());
            material.setReplayUrl(couMaterial.getReplayUrl());
            //直播数据，结束

            //文章数据，开始
            material.setArticleSummary(couMaterial.getArticleSummary());
            material.setArticleContext(couMaterial.getArticleContext());
            //文章数据，结束

            material.setPlayType(couMaterial.getPlayType());
            material.setName(couMaterial.getName());
            material.setSubjectIds(couMaterial.getSubjectIds());
            material.setMouldId(couMaterial.getMouldId());
            material.setTeacherId(couMaterial.getTeacherId());
            //修改状态
            if(couMaterial.getStatus()!=null && couMaterial.getStatus().intValue()==2
                    && (material.getStatus().intValue()==0 || material.getStatus().intValue()==1)){
                material.setStatus(couMaterial.getStatus());
            }
            this.updateById(material,null);
        }else{//添加
            this.save(couMaterial);
        }
        return couMaterial;
    }

    /**
     * 分页查询素材数据
     * @param couMaterialCondition 查询条件对象
     * @param page 分页条件
     * @param setSubjectData
     * @param setTeacherData
     * @return PageInfo<CouMaterial>
     */
    public PageInfo<CouMaterial> findMaterialPage(CouMaterialCondition couMaterialCondition, Pagination page,
                                                  boolean setSubjectData,boolean setTeacherData){
        PageInfo<CouMaterial> couMaterialPageInfo = null;
        if(couMaterialCondition.getType() ==2 || couMaterialCondition.getType() ==1){
            if(StringUtils.isNotEmpty(couMaterialCondition.getSubjectIds())){
                String subjectSql = StringUtils.getSubjectSql("couMaterial.subjectIds",couMaterialCondition.getSubjectIds());
                couMaterialCondition.setSubjectSql(subjectSql);
            }
            if(couMaterialCondition.getType() ==2) {
                //查询课程目录可以选择的素材列表
                couMaterialPageInfo = findCourseCatalogMaterialList(couMaterialCondition,page);
            }
            if(couMaterialCondition.getType() ==1) {
                //查询课模块可以选择的素材列表
                couMaterialPageInfo = findMouldMaterialList(couMaterialCondition, page);
            }
        }else{
            String whereSql = this.getWhereSql(couMaterialCondition);
            whereSql += " order by createTime desc";
            couMaterialPageInfo = this.findPage(whereSql,page,null);
        }
        this.setCouMaterialExData(couMaterialPageInfo.getList(),setSubjectData,setTeacherData);
        return couMaterialPageInfo;
    }

    /**
     * 查询课程设置目录的素材
     * @param couMaterialCondition 查询条件
     * @return  Page<CouMaterial>
     */
    private PageInfo<CouMaterial> findCourseCatalogMaterialList(CouMaterialCondition couMaterialCondition,Pagination page){
        PageHelper.startPage(page.getCurrentPage(),page.getPageSize());
        Page<CouMaterial> dataList = couMaterialDao.findCourseCatalogMaterialList(CouMaterial.class,couMaterialCondition);
        PageInfo<CouMaterial> pageInfo = new PageInfo<CouMaterial>(dataList); //默认导航显示页数8
        return pageInfo;
    }

    /**
     * 查询模块设置的素材列表
     * @param couMaterialCondition 查询条件
     * @return  Page<CouMaterial>
     */
    private PageInfo<CouMaterial> findMouldMaterialList(CouMaterialCondition couMaterialCondition,Pagination page){
        PageHelper.startPage(page.getCurrentPage(),page.getPageSize());
        Page<CouMaterial> dataList = couMaterialDao.findMouldMaterialList(CouMaterial.class,couMaterialCondition);
        PageInfo<CouMaterial> pageInfo = new PageInfo<CouMaterial>(dataList); //默认导航显示页数8
        return pageInfo;
    }

    /**
     * 多条件查询素材数据列表
     * @param condition 查询条件
     * @param setSubjectData
     * @param setTeacherData
     * @return List<CouMaterial>
     */
    public List<CouMaterial> findMaterialList(CouMaterialCondition condition,
                                              boolean setSubjectData,boolean setTeacherData){
        String whereSql = this.getWhereSql(condition);
        List<CouMaterial> couMaterialList = this.find(whereSql,condition.getCount(),null);
        this.setCouMaterialExData(couMaterialList,setSubjectData,setTeacherData);
        return couMaterialList;
    }

    /**
     * 通过多条件查询素材Mpa
     * @param condition 查询条件
     * @param setSubjectData
     * @param setTeacherData
     * @return Map<BigDecimal,CouMaterial>
     */
    public Map<BigDecimal,CouMaterial> findMaterialToIdMap(CouMaterialCondition condition,
                                                           boolean setSubjectData,boolean setTeacherData){
        List<CouMaterial> couMaterials = this.findMaterialList(condition,setSubjectData,setTeacherData);
        if(ObjectUtils.isNotEmpty(couMaterials)){
            return couMaterials.stream().collect(Collectors.toMap(e->e.getId(),e->e));
        }
        return null;
    }

    public CouMaterial findMaterialById(BigDecimal id,
                                        boolean setSubjectData,boolean setTeacherData){
        List<CouMaterial> couMaterials = this.findMaterialByIds(id.toString(),setSubjectData,setTeacherData);
        if(ObjectUtils.isNotEmpty(couMaterials)){
            return couMaterials.get(0);
        }
        return null;
    }

    public List<CouMaterial> findMaterialByIds(String ids,
                                        boolean setSubjectData,boolean setTeacherData){
        CouMaterialCondition condition = new CouMaterialCondition();
        condition.setIds(ids);
        return this.findMaterialList(condition,setSubjectData,setTeacherData);
    }

    /**
     * 通过ID串，查询素材Map
     * @param ids 尖串
     * @param setSubjectData
     * @param setTeacherData
     * @return
     */
    public Map<BigDecimal,CouMaterial> findMaterialByIdsToMap(String ids,
                                               boolean setSubjectData,boolean setTeacherData){
        CouMaterialCondition condition = new CouMaterialCondition();
        condition.setIds(ids);
        return this.findMaterialToIdMap(condition,setSubjectData,setTeacherData);
    }

    /**
     * 修改素材状态235
     * @param updateList 要修改的素材列表
     * @param deleteList 要真删除的素材数据
     * @param status 状态，1未发布，2已发布，3删除
     */
    @Transactional(rollbackFor =  IllegalArgumentException.class)
    public void updateMaterialStatus(List<CouMaterial> updateList , List<CouMaterial> deleteList, int status){
        String updateIds = null;
        if(status ==1 || status== 2){
            if(ObjectUtils.isNotEmpty(updateList)){//修改的
                updateIds = updateList.stream().map(e->e.getId().toString()).collect(Collectors.joining(","));

            }
        }
        if(3 == status){
            if(ObjectUtils.isNotEmpty(deleteList)){//真删除的
                String deleteIds = deleteList.stream().map(e->e.getId().toString()).collect(Collectors.joining(","));
                this.deleteWhereSql(" id in ("+deleteIds+")");
            }
            if(ObjectUtils.isNotEmpty(updateList)){//修改的
                updateIds = updateList.stream().map(e->e.getId().toString()).collect(Collectors.joining(","));
            }
        }
        if(StringUtils.isNotEmpty(updateIds)){//执行修改
            CouMaterial couMaterial = new CouMaterial();
            couMaterial.setStatus(status);
            this.updateByWhereSql(couMaterial," id in ("+updateIds+")");
        }
    }

    /**
     * 修改素材浏览/播放状态
     * @param materialIds 素材ID串
     * @param playStatus 状态，1正常，2冻结
     */
    public void updateMaterialPlayStatus(String materialIds,int playStatus){
        if(StringUtils.isNotEmpty(materialIds)){
            materialIds = StringUtils.subHeadTailString(materialIds,",");
            if(StringUtils.isNotEmpty(materialIds) && (playStatus==1 || playStatus==2)){
                CouMaterial material = new CouMaterial();
                material.setPlayStatus(playStatus);
                this.updateByWhereSql(material," id in ("+materialIds+")");
            }
        }
    }


    /**
     * 查询今日直播数据用于后台待办事项
     * @return  Page<CouMaterial>
     */
    public  List<CouMaterial>  findBacklogLiveList(String start,String end){
        Map<String,String> param=new HashMap<>();
        param.put("start", start);
        param.put("end", end);
        param.put("status", "2");

        List<CouMaterial> backlogLiveList = couMaterialDao.findBacklogLiveList(CouMaterial.class, param);
        this.setTeacherData(backlogLiveList,true);
        return backlogLiveList;
    }
    //=====================================================================================================

    /**
     * 获取SQL查询条件
     * @param condition 条件对象
     * @return 条件SQL
     */
    private String getWhereSql(CouMaterialCondition condition){
        StringBuilder whereSql = new StringBuilder(" status!=3");
        if(ObjectUtils.isNotEmpty(condition)){
            if(StringUtils.isNotEmpty(condition.getIds())){
                String ids = condition.getIds();
                ids = StringUtils.subHeadTailString(ids,",");
                whereSql .append(" and id in (").append(ids).append(")");
            }
            if(StringUtils.isNotEmpty(condition.getSubjectIds())){
                whereSql .append( StringUtils.getSubjectSql("subjectIds",condition.getSubjectIds()));
            }
            if(StringUtils.isNotEmpty(condition.getName())){
                whereSql .append(" and name like '%").append(condition.getName().trim()).append("%'");
            }
            if(condition.getStatus()!=null){
                whereSql .append(" and status = ").append(condition.getStatus());
            }
            if(StringUtils.isNotEmpty(condition.getTypeKey())){
                whereSql .append(" and typeKey ='").append(condition.getTypeKey().trim()).append("'");
            }
            if(StringUtils.isNotEmpty(condition.getPlayType())){
                whereSql .append(" and playType = '").append(condition.getPlayType().trim()).append("'");
            }
            if (StringUtils.isNotEmpty(condition.getNowDate())){
                SimpleDateFormat time1 = new SimpleDateFormat("yyyy-MM-dd");
                whereSql = new StringBuilder();
                whereSql.append(" status = ").append(condition.getStatus()).append(" and liveBeginTime >= '" ).append(time1.format(condition.getNowDate())).append(" 00:00:00'").append(
                        " and liveEndTime <= '").append(time1.format(condition.getNowDate())).append( " 23:59:59'");
            }
        }
        return whereSql.toString();
    }

    /**
     * 设置素材扩展数据
     * @param couMaterialList
     * @param setSubjectData
     * @param setTeacherData
     * @return
     */
    private List<CouMaterial> setCouMaterialExData(List<CouMaterial> couMaterialList,boolean setSubjectData,boolean setTeacherData){
        if(ObjectUtils.isNotEmpty(couMaterialList)){
            if(setSubjectData){
                couMaterialList = commonSetSubjectDataService.setSubjectData(subjectService,couMaterialList,setSubjectData);
            }
            if(setTeacherData){
                couMaterialList = this.setTeacherData(couMaterialList,setTeacherData);
            }
        }
        return couMaterialList;
    }

    /**
     * 设置讲师数据
     * @param couMaterialList
     * @param setTeacherData
     * @return
     */
    private List<CouMaterial> setTeacherData(List<CouMaterial> couMaterialList,boolean setTeacherData){
        if(ObjectUtils.isNotEmpty(couMaterialList) && setTeacherData){
            String teacherIds = couMaterialList.stream().map(e->e.getTeacherId().toString()).collect(Collectors.joining(","));
            Map<BigDecimal,Map<String,Object>> teacherMaps = sysTeacherService.findSysTeacherToMapByIds(teacherIds,false,false,false, false, false);
            if(ObjectUtils.isNotEmpty(teacherMaps)){
                couMaterialList.forEach(e->{
                    Map<String,Object> teacher = teacherMaps.get(e.getTeacherId());
                    e.setTeacher(teacher);
                });
            }
            String assistantIds = couMaterialList.stream().map(e->e.getAssistantId().toString()).collect(Collectors.joining(","));
            Map<BigDecimal,Map<String,Object>> assistantMaps = sysTeacherService.findSysTeacherToMapByIds(assistantIds,false,false,false, false, false);
            if(ObjectUtils.isNotEmpty(assistantMaps)){
                couMaterialList.forEach(e->{
                    Map<String,Object> assistant = assistantMaps.get(e.getAssistantId());
                    e.setAssistant(assistant);
                });
            }
        }
        return couMaterialList;
    }

    /**
     *
     *
     * @param sysUserId
     * @return
     */
    public List<Map<String, Object>> listTodayMaterialLive(BigDecimal sysUserId) {
       /* String condition = SingletonLoginUtils.getSysUserSubjectIds(sysUserId);
        if (StringUtils.isEmpty(condition)) {
            return Collections.emptyList();
        }
        String where = " liveEndTime >= '" + DateUtils.getNowStrLong() + "' and playStatus = 1 and status = 2 and typeKey = 'LIVE' and subjectId in (" + condition + ")";
        List<CouMaterial> materials = couMaterialBiz.find(where, null, null);
        couMaterialBiz.setMaterialPlayState(materials);
        this.setMaterialCurrentTeacherBool(materials, sysUserId);
        String json = GsonUtil.toJson(materials, true);
        return GsonUtil.fromJson(json, new TypeToken<List<Map<String, Object>>>() {
        });*/
       return  null;
    }

    private void setMaterialCurrentTeacherBool(List<CouMaterial> materialList, BigDecimal sysUserId) {
       /* if (ObjectUtils.isNotEmpty(sysUserId) && ObjectUtils.isNotEmpty(materialList)) {
            Map<BigDecimal, Map<String, Object>> teacherMap = sysHessianService.getTeacherBySysUser(sysUserId);
            if (ObjectUtils.isNotEmpty(teacherMap)) {
                Map<String, Object> teacher = teacherMap.get(sysUserId);
                BigDecimal teacherId = teacher.getOrDefault("id", 0);
                materialList.forEach((v) -> v.setTeacher(teacherId));
            }
        }*/
    }

    /**
     * 下载导入模板
     * @param materialType 素材类型，视频/音频
     * @param subjectIds 专业ID串
     * @return 返回模板文件
     * @throws Exception
     */
    public ResponseEntity<byte[]> downloadMaterialTemplate(String materialType, String subjectIds,String playType) throws Exception {
        //创建工作簿
        Workbook workbook = new XSSFWorkbook();
        CellStyle red = workbook.createCellStyle();
        Font font = workbook.createFont();
        font.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
        red.setFont(font);
        CellStyle black = workbook.createCellStyle();
        Font fontTWo = workbook.createFont();
        fontTWo.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
        fontTWo.setBold(true);
        black.setFont(fontTWo);
        String[] materialTypes = getMaterialType(materialType,playType);
        //创建模版工作表
        createExcelSheet(workbook,materialTypes,materialType, subjectIds,playType,red,black);
        //查找专业对应的讲师信息
        String whereSql = "1=1"+StringUtils.getSubjectSql("subjectIds",subjectIds);
        Map<BigDecimal,String> teacherMap = sysTeacherService.findTeacherToMapList(whereSql,false,false,false);
        //创建模版中所选专业对应的讲师信息工作表
        createExcelSheet1(workbook,teacherMap,red,black);
        //写出文件
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        workbook.write(baos);
        String fileName = materialType + System.currentTimeMillis() + ".xlsx";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<>(baos.toByteArray(), headers, HttpStatus.OK);
    }

    /**
     * 创建模版工作表
     * @param workbook 工作簿
     * @param materialTypes 素材字段字符串数组
     * @param materialType 播放类型
     * @param subjectIds 专业/科目ID串
     * @param playType 播放云服务
     * @param red 单元格字体红色
     * @param black 单元格字体黑色
     */
    private void createExcelSheet(Workbook workbook,String[] materialTypes,String materialType, String subjectIds,String playType,CellStyle red,CellStyle black) throws Exception {
        Sheet sheet = workbook.createSheet(materialTypes[0]+"模版");
        setSheetStyleToString(workbook,sheet,materialTypes.length);
        Row row = sheet.createRow(0);
        createCell(row, "素材类型", 0, black);
        createCell(row, materialTypes[0], 1, black);
        createCell(row, "专业科目", 2, black);
        createCell(row, subjectIds, 3, black);
        if(!materialType.equals(MaterialType.TYPE_KEY_ARTICLE.getKey())){
            createCell(row, "云服务商", 4, black);
            createCell(row, playType, 5, black);
        }
        row = sheet.createRow(1);
        createCell(row, "素材名称", 0, red);
        createCell(row, "讲师ID（请到《专业对应讲师信息》工作表查询对应ID）", 1, red);

        for(int i=2;i<materialTypes.length;i++){
            createCell(row, materialTypes[i], i, red);
        }

            String url = environment.getProperty("static.path")+"/admin/v3/img/material/prompt.png";
            InputStream   is = FileDownloadUtil.getInputStream(url);
            byte[] bytes = IOUtils.toByteArray(is);

            int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);

            CreationHelper helper = workbook.getCreationHelper();
            Drawing drawing = sheet.createDrawingPatriarch();
            ClientAnchor anchor = helper.createClientAnchor();
            // 图片插入坐标
            anchor.setCol1(0);
            anchor.setRow1(6);
            // 插入图片
            Picture pict = drawing.createPicture(anchor, pictureIdx);
            pict.resize();
    }

    /**
     * 创建专业对应的讲师信息工作表
     * @param workbook 工作簿
     * @param teacherMap 讲师信息Map
     * @param black 单元格字体黑色
     */
    private void createExcelSheet1(Workbook workbook,Map<BigDecimal,String> teacherMap,CellStyle red,CellStyle black){
        Sheet sheet = workbook.createSheet("专业对应的讲师信息");
        setSheetStyleToString(workbook,sheet,3);
        Row row = sheet.createRow(0);
        createCell(row,"讲师名",0,black);
        createCell(row,"讲师ID",1,black);
        int rowCount = 1;
        if(ObjectUtils.isEmpty(teacherMap)){
            createCell(row,"当前所选专业还没有对应讲师",2,red);
        }else{
            for(Map.Entry<BigDecimal,String> entry : teacherMap.entrySet()){
                row = sheet.createRow(rowCount);
                createCell(row,entry.getValue(),0,black);
                createCell(row,entry.getKey().toString(),1,black);
                rowCount++;
            }
        }
    }

    /**
     * 设置工作表列默认格式
     * @param wb 工作簿
     * @param sheet 工作表
     * @param colNums 列数
     */
    private void setSheetStyleToString(Workbook wb,Sheet sheet,int colNums){
        CellStyle textStyle = wb.createCellStyle();
        DataFormat format = wb.createDataFormat();
        textStyle.setDataFormat(format.getFormat("@"));
        for(int i=0;i<colNums;i++){
            sheet.setDefaultColumnStyle(i,textStyle);
        }
        sheet.setDefaultColumnWidth(23);
    }

    /**
     * 获取素材类型对应的字段名
     * @param materialType
     * @return
     */
    private String[] getMaterialType(String materialType,String playType) {
        if(materialType.equals(MaterialType.TYPE_KEY_VIDEO.getKey())){
            return new String[]{MaterialType.TYPE_KEY_VIDEO.getValue(), "讲师ID", "视频码"};
        }else if(materialType.equals(MaterialType.TYPE_KEY_AUDIO.getKey())){
            return new String[]{MaterialType.TYPE_KEY_AUDIO.getValue(), "讲师ID", "音频码"};
        }else if(materialType.equals(MaterialType.TYPE_KEY_ARTICLE.getKey())){
            return new String[]{MaterialType.TYPE_KEY_ARTICLE.getValue(), "讲师ID","文章简介", "文章内容"};
        }else if(materialType.equals(MaterialType.TYPE_KEY_LIVE.getKey())){
            if(playType.equals("96K")){
                return new String[]{MaterialType.TYPE_KEY_LIVE.getValue(), "讲师ID", "直播间识别码", "直播间ID", "讲师参加码", "学员参加码", "管理员参加码", "直播开始时间\n（如：2018-12-08 12:12:12）", "直播结束时间\n（如：2018-12-08 13:12:12）"};
            }else{
                return new String[]{MaterialType.TYPE_KEY_LIVE.getValue(), "讲师ID", "直播间识别码", "学员参加码", "直播开始时间\n（如：2018-12-08 12:12:12）", "直播结束时间\n（如：2018-12-08 13:12:12）"};
            }
        }else{
            return new String[]{"", ""};
        }
    }

    /**
     * 创建单元格
     * @param row 行
     * @param value 值
     * @param index 列
     * @param style 格式
     */
    private void createCell(Row row, String value, int index, CellStyle style) {
        Cell cell = row.createCell(index);
        style.setWrapText(true);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setAlignment(HorizontalAlignment.LEFT);
        cell.setCellStyle(style);
        cell.setCellValue(value);
    }

    /**
     * 执行导入素材文件
     * @param couMaterials 素材内容文件
     * @return Map<String, Object>
     */
    @Transactional(rollbackFor =  IllegalArgumentException.class)
    public Map<String, Object> uploadMaterial(List<CouMaterial> couMaterials) {
        this.batchSave(couMaterials);
        return ResultUtil.SUCCESS("上传成功");
    }

}
